# vars
# -------------------------------------------------------------
srmpkg='gys-external-srm'
invoicepkg='gys-external-invoice'
costpkg='gys-external-cost'

brsrcBuildIntOfuat='sit' # gys-external-invoice uat包基于哪个分支构建
brsrcBuildIntOfprod='prod-isp-temp' # gys-external-invoice prod包基于哪个分支构建

# brbuildingIntOfuat='build-invoiceLib-ondev'  # 从uat拉，合并sit过来
brbuildingIntOfuat='build-invoiceLib-ondev'  # 从sit拉
brbuildingIntOfprod='build-invoiceLib-online' # 从prod-isp-temp拉

# brmy='cmp-release-buildMergeRelease'
brmy='cmp-build'
brrelease='cmp-release'

pkDircost="/d/bgy/projects/gys-external-cost"
pkDirsrm="/d/bgy/projects/gys-external-srm"
pkDirinvoice="/d/bgy/projects/gys-external-invoice"


# alias wk="cd /d/bgy/projects/group-integrationiplatform-frontend"
# alias wksrm="cd /d/bgy/projects/group-integrationiplatform-frontend/projects/yth-srm"
# alias wkinvoice="cd /d/bgy/projects/group-integrationiplatform-frontend/projects/yth-integration"
# alias wkcost="cd /d/bgy/projects/group-integrationiplatform-frontend/projects/yth-co"
wkDir="/d/bgy/projects/group-integrationiplatform-frontend"
wksrmDir="/d/bgy/projects/group-integrationiplatform-frontend/projects/yth-srm"
wkinvoiceDir="/d/bgy/projects/group-integrationiplatform-frontend/projects/yth-integration"
wkcostDir="/d/bgy/projects/group-integrationiplatform-frontend/projects/yth-co"

wkDirAsrm="/d/bgy/projects/yth-srm"
wkDirAco="/d/bgy/projects/yth-co"
wkDirAint="/d/bgy/projects/yth-integration"

declare -A wkdirsMap
wkdirsMap['all']="$wkDir"
wkdirsMap['srm']="$wkDirAsrm"
wkdirsMap['cost']="$wkDirAco"
wkdirsMap['invoice']="$wkDirAint"

function wk() {
    usage 1 ${#@} "wk [srm | cost | invoice | all]" || return 1
    local pkshortName="${1-all}"
    local projWkDir="${wkdirsMap[$pkshortName]}"

    # 未切换前 固定设置为 all
    # projWkDir="${wkdirsMap['all']}"

    cd $projWkDir
    lnlog "切换到项目所在文件夹: $projWkDir"
}

function wksrm() {
    wk srm
    cd ./projects/yth-srm
}
function wkinvoice() {
    wk invoice
    cd ./projects/yth-integration
}

function wkcost() {
    wk cost
    cd ./projects/yth-co
}


alias pkcost="cd $pkDircost"
alias pksrm="cd $pkDirsrm"
alias pkinvoice="cd $pkDirinvoice"

alias wkbuild='cd /d/bgy/build-server'
alias bserve='wkbuild && node server.js'


# git
alias gp="git pull origin"
alias gpp="git pull origin && git push origin"
alias gapp="git pull origin --no-edit && git push origin"
alias gco="git checkout"
alias gcp="git cherry-pick"
alias gs="git status"
alias gb="git branch"
alias gcm="git commit -m"
alias gcma="git add . && git commit -am"
alias ga="git add"
alias gl="git log"
alias gm='git merge'
alias glol='git log --oneline'
alias glmol='git log --author=pan --oneline'

# work branch
alias gcomy="git checkout $brmy"
alias gcorelease="git checkout $brrelease"
alias gcoBuildingIntOfuat="gco $brbuildingIntOfuat"
alias gcoBuildingIntOfprod="gco $brbuildingIntOfprod"
alias gcobuild="gco $brbuildingIntOfuat"
alias gcopbuild="gco $brbuildingIntOfprod"

alias gcomain="git checkout $brmain"
alias gcoboth="git checkout $brboth"
alias gcome="nwksrm && git checkout feat-panzj"
alias glme='gl -20 --author pan  --oneline'
alias gcoall="git checkout $brall"

# alias mgfrombuild="gco $brmy && gp && gco - && gm  --no-edit $brmy && gpp"
# alias mgtobuild="gco $brmy && gp && gm --no-edit feat-panzj && gpp"


# cmp build
alias autoall='autolib dev && autolib uat'


# utils
# -------------------------------------------------------------
function clog() {
    echo -e "[INFO]▶ $@ "
}

function lnlog() {
    echo -e "\n [LOG]▶ $1 \n"
}


function usage() {
    local expectArgs="$1"
    local actualArgs="$2"
    local msg="$3"
    if [ $actualArgs -lt $expectArgs ]; then
        # echo "args: ${@}"
        lnlog "usage: $msg"
        return 1
    fi
}


function mergeBranch() {
    usage 2 ${#@} "mergeBranch <fromBranch> <toBranch> [noAbortMerge]" || return 1
    
    local fromBranch="$1"
    local toBranch="$2"
    local noAbortMerge="$3"
    
    git checkout $toBranch
    git merge $fromBranch --no-edit
    
    if [ $? -gt 0 ]; then
        if [ "$noAbortMerge" == "yes" ]; then
            lnlog "$fromBranch 合并到 $toBranch 发生冲突，请解决冲突..."
        else
            lnlog "$fromBranch 合并到 $toBranch 发生冲突，撤销合并..."
            git merge --abort
        fi
        return 1
    fi
    
    lnlog "成功合并分支 $fromBranch -->  $toBranch !"
}

function checkoutBranch() {
    local branch="$1"
    git branch | grep $branch > /dev/null
    if [ $? -gt 0 ]; then
        lnlog "检出分支 $branch ..."
        git remote update
        git checkout --track origin/$branch
        if [ $? -gt 0 ]; then
            lnlog "检出失败，分支 $branch 不存在，请检查拼写"
            return 1
        else
            lnlog "成功检出分支 $branch"
        fi
    else
        
        git checkout $branch
        
        git pull --no-edit
        if [ $? -gt 0 ]; then
            lnlog "拉取 $branch 分支代码发生冲突!!, 取消操作, 请手动同步"
            return 1
        else
            lnlog "成功切换到分支 $branch , 并拉取最新代码"
        fi
    fi
    
}

function pullAndPushBranch() {
    local branch="$1"
    git checkout $branch
    git pull --no-edit
    if [ $? -gt 0 ]; then
        lnlog "$branch 分支拉取最新代码冲突, 回退操作"
        return 1
    fi
    git push
}



# build-utils
# -------------------------------------------------------------

function showlog() {
    echo "<br/></br>"
    
    git log -30 --oneline | grep -v "升级gys-external" | grep -v "Merge branch" | grep -v "保存构建版本"
    
    echo "<br/></br>"
}

function wkproject() {
    local pkshortName=${1-srm}
    if [ "$pkshortName" = 'srm' -o "$pkshortName" = 'invoice' -o "$pkshortName" = 'cost' ]; then
        local cmd="wk${pkshortName}"
        eval $cmd
        
        clog "项目切换到文件夹 $(getpwd)"
    else
        echo "wkproject 参数非法 ${pkshortName}"
        return 1
    fi
}

function pkproject() {
    local pkshortName=${1-srm}
    if [ "$pkshortName" = 'srm' -o "$pkshortName" = 'invoice' -o "$pkshortName" = 'cost' ]; then
        local cmd="pk${pkshortName}"
        eval $cmd
        # local curdir=$(pwd)
        # clog "Lib切换到文件夹 ${curdir:7}"
    else
        echo "pkproject 参数非法 ${pkshortName}"
        return 1
    fi
}

function taglib() {
    local pkshortName=${1-srm}
    local upperPkName=${pkshortName^^}

    clog "准备给构建分支打tag"
    
    wkproject $pkshortName || return 1
    
    local gtag=`grep "const ${upperPkName}_VERSION" src/index.js | sed "1s/^[a-z A-Z_=\']*//" | sed "1s/'//g" | sed "1s/@.*//"`
    echo $gtag
    
    gcma "task#${taskId}: 保存构建版本 $gtag "
    git tag $gtag
    
    clog "项目仓库添加 tag done"
    
    # git tag  | head -5
    
    clog "项目仓库推送tag到远端"
    
    git push origin --tags
    
}


function pullib() {
    usage 1 ${#@} "pullib <branch> [pkname]"
    
    local pkshortName=${2-srm}
    
    local branch="$1"
    
    wkproject $pkshortName || return 1
    cd ..
    git checkout .
    cd -

    git checkout $branch
    git pull --no-edit
    
    if [ $? -gt 0 ]; then
        lnlog "拉取分支 $branch 发生冲突，回退pull操作"
        git merge --abort
        git status
        return 1
    fi
    
    lnlog "同步分支 ${branch} 最新提交成功!"
    
    showlog
}


function mglib() {
    usage 3 ${#@} "mglib <pkshortName> <fromBranch> <toBranch> " || return 1
    
    local pkshortName=${1}

    wkproject $pkshortName || return 1

    cd ..
    gco .
    cd - > /dev/null
    
    # gcomy
    
    local fromBranch="$2"
    local toBranch="$3"
    
    checkoutBranch $fromBranch || return 1
    checkoutBranch $toBranch || return 1
    
    
    mergeBranch $fromBranch $toBranch || return 1
    
    
    pullAndPushBranch $toBranch || return 1
    
    showlog
}

function getpwd() {
    local curdir=`pwd`
    local tmpdir=${curdir/*\/group/group}
    echo ${tmpdir/*\/yth/yth}
}

function createPackDepsFile() {
    usage 1 ${#@} "createPackDepsFile <pkname>" || return 1
    local fname='packageDeps.lock.js'
    local pkshortName="${1}"
    wk $pkshortName || return 1

    # cd ../..

    clog "当前目录: `getpwd`"

    if [ ! -f "$fname" ]; then
        echo "module.exports = " > $fname
        cat package.json >> $fname
        clog "创建 $fname done"
    else
        clog "$fname 已存在"
        return 0
         
    fi

    # cd - > /dev/null
}

function checkNewPackageDeps() {
    usage 1 ${#@} "checkNewPackageDeps <pkname>" || return 1
    local fname='packageDeps.lock.js'
    local pkshortName="$1"
    # wkproject $pkshortName || return 1
    wk $pkshortName || return 1
    # cd ../..

    if [ ! -f $fname ]; then
        clog "$fname 不存在!"
        return 1
    else
        local newPackages=`bash packageDepsCheck.lock.sh`
        if [ -z "$newPackages" ]; then
            clog "没有发现新的依赖"
        else
            cmd="yarn add $newPackages -W"
            clog "发现新依赖并安装 $cmd"
            $cmd
            clog "安装依赖后，删除旧文件 $fname "
            rm $fname;
        fi
    fi

    # cd - > /dev/null

    if [ -n "$newPackages" ]; then
        createPackDepsFile $pkshortName || return 1
    fi

}

# build-srm
# -------------------------------------------------------------

function autolib() {
    usage 2 ${#@} "autolib <fromBranch> <dev | uat | master>" || return 1
    
    local fromBranch="$1"
    local libBranch="$2"
    local buildingBranch=''

    createPackDepsFile srm || return 1

    if [ "$fromBranch" != "noneed" ]; then
        if [ $libBranch = 'dev' -o $libBranch = 'uat' ]; then
            buildingBranch=$brmy
            mglibSrmToDev $fromBranch || return 1
        else
            buildingBranch=$brrelease
            mglibSrmToProd $fromBranch || return 1
        fi
    else
        if [ $libBranch = 'dev' -o $libBranch = 'uat' ]; then
            buildingBranch=$brmy
            pullib $brmy || return 1
        else
            buildingBranch=$brrelease
            pullib $brrelease || return 1
        fi
        
        lnlog "没有输入功能分支，默认已手动合并到 ${buildingBranch} !"
    fi

    checkNewPackageDeps srm || return 1

    mklib $libBranch && cplib $libBranch && pblib $libBranch && taglib
    
}


function mklib() {
    usage 1 ${#@} "mklib <dev | uat | master>" || return 1
    
    local libBranch="$1"
    local tag="$libBranch"
    
    if [ "$libBranch" = "master" ]; then
        tag="latest"
    fi
    
    clog "当前构建的是 $libBranch 版本"
    clog "gys-external-cost 已设置为externals依赖"
    
    pksrm
    
    git checkout $libBranch
    clog "Lib仓库切换到分支 $libBranch done"
    
    
    local newVersion=`bash upversion.sh`
    # clog "新的版本号为: $newVersion"
    
    wksrm
    
    local dt=`date +%Y-%m-%dT%H:%M:%S`
    sed -i "/SRM_VERSION/s/'[^\']*'/'${newVersion}@RTIME${dt}'/" ./src/index.js
    grep "SRM_VERSION" ./src/index.js
    
    clog "index.js写入新版本号 $newVersion done"
    
    local env="${libBranch}"
    if [ "${libBranch}" = "dev" ]; then
        env="sit"
    elif [ "${libBranch}" = "master" ]; then
        env="prod"
    fi
    
    prefix="./lib/${env}/"
    rm -rf "${prefix}/*"
    clog "项目仓库清理旧构建产物 done!"
    
    
    if [ "$env" = "dev" -o "$env" = "sit" ]; then
        cmd="lib:sit"
        clog "切换到打包分支 $brmy"
        git checkout $brmy
        gp
    elif [ "$env" = "uat" ]; then
        cmd="lib:uat"
        clog "切换到打包分支 $brmy"
        git checkout $brmy
        gp
    else
        cmd="lib:prod"
        clog "切换到打包分支 $brrelease"
        git checkout $brrelease
        gp
    fi
    
    clog "执行打包命令 $cmd"
    
    
    yarn $cmd
    
}


function cplib() {
    usage 1 ${#@} "cplib <dev | uat | master>" || return 1
    
    local libBranch="$1"
    
    local env="${libBranch}"
    if [ "${libBranch}" = "dev" ]; then
        env="sit"
        elif [ "$libBranch" = "master" ]; then
        env="prod"
    fi
    
    wk srm || return 1
    targetDir="${pkDirsrm}/lib"
    mkdir -p $targetDir
    rm -rf ${targetDir}/*
    ls -a ${targetDir}
    clog 'Lib仓库清理旧文件 done'
    
    
    pksrm
    
    gco $libBranch
    clog "Lib仓库切换到分支 $libBranch done"
    
    wk srm || return 1
    prefix="./projects/yth-srm/lib/${env}/"
    
    clog "构建产物所在文件夹为: ${prefix}"
    
    
    isAll="yes"
    if [ "$isAll" ]; then
        cp -r ${prefix}/*  "${targetDir}/"
    else
        
        ls $prefix | grep -vE "/$" | grep -vE  "[0-9]+\.js$" | grep -v "html" | xargs -i   -exec cp -r ${prefix}/{} "${targetDir}/"
    fi
    
    clog '构建产物复制到Lib仓库 done'
    # ls -a ${targetDir}
    
    pksrm
    
    gcma "更新lib文件"
    newVersion=`bash ./upversion.sh`
    npm version $newVersion
    
    cLog "更新到新的版本 $newVersion done!"
    
    gapp
    
    clog "推送Lib仓库的变更到远端 done"
}


function pblib() {
    usage 1 ${#@} "pblib <dev | uat | master>" || return 1
    
    
    echo registry:  `npm get registry`
    echo user: `npm whoami`
    
    # read -p '确认继续发布吗？[y/n]: '  answer
    answer='y'
    
    if [ "$answer" != "y" ]; then
        echo 88
        return 2
    fi
    
    local branch="$1"
    local tag="$branch"
    
    if [ "$branch" = "master" ]; then
        tag='latest'
    fi
    
    pksrm
    clog "切换分支到 ${branch}"
    gco $branch
    
    clog "开始发布 ${tag} 版本"
    local cmd="npm publish --tag ${tag}"
    
    clog "发布命令: ${cmd}"
    npm publish --tag $tag
    if [ $? -ne 0 ]; then
        clog "发布失败"
    else
        clog "发布完成"
        npm info $srmpkg | head -30
    fi
    
}


function mglibSrm() {
    usage 2 ${#@} "mglibSrm <fromBranch> <toBranch>" || return 1
    
    local fromBranch="$1"
    local toBranch="$2"
    mglib srm $fromBranch $toBranch
}


function mglibSrmToDev() {
    usage 1 ${#@} "mglibSrmToDev <branch>" || return 1
    
    local branch="$1"
    mglibSrm "$branch" $brmy
}


function mglibSrmToProd() {
    usage 1 ${#@} "mglibSrmToProd <branch>" || return 1
    
    local branch="$1"
    mglibSrm $branch $brrelease
}



# build-invoice
# -------------------------------------------------------------

function intautolib() {
    usage 3 ${#@} "intautolib <fromBranch> <dev | uat | prod> <pkname>" || return 1
    
    local fromBranch="$1"
    local libBranch="$2"
    local srcBuildBranch=''
    local pkshortName=${3}

    createPackDepsFile $pkshortName || return 1

    if [ "$fromBranch" != "noneed" ]; then
        if [ $libBranch = 'dev' -o $libBranch = 'uat' ]; then
            srcBuildBranch=$brsrcBuildIntOfuat
            mglib $pkshortName $fromBranch $brsrcBuildIntOfuat || return 1
        else
            srcBuildBranch=$brsrcBuildIntOfprod
            mglib $pkshortName $fromBranch $brsrcBuildIntOfprod || return 1
        fi
    else
        if [ $libBranch = 'dev' -o $libBranch = 'uat' ]; then
            srcBuildBranch=$brsrcBuildIntOfuat
            pullib $brsrcBuildIntOfuat $pkshortName || return 1
        else
            srcBuildBranch=$brsrcBuildIntOfprod
            pullib $brsrcBuildIntOfprod $pkshortName || return 1
        fi
        
        lnlog "没有输入功能分支，默认已手动合并到 ${srcBuildBranch} !"
    fi

    checkNewPackageDeps $pkshortName || return 1

    intmklib $libBranch $pkshortName && intcplib $libBranch $pkshortName && intpublib $libBranch $pkshortName && taglib $pkshortName
    # intmklib $libBranch $pkshortName
    
}

function intmklib() {
    usage 2 ${#@} "intmklib <dev | uat | prod> <pkname>" || return 1

    local pkshortName=${2}
    local upperPkName=${pkshortName^^}
    wkproject $pkshortName || return 1
    
    local env="$1"
    local cmdEnv="$env"
    local branch=""
    if [ "$env" == "uat" -o "$env" == "dev" ]; then
        branch="$brbuildingIntOfuat"
        
        # 基于sit分支 构建uat版本的组件包
        # checkoutBranch $brsrcBuildIntOfuat
        # gp --no-edit || return 1
        checkoutBranch $brsrcBuildIntOfuat || return 1
        checkoutBranch $brbuildingIntOfuat || return 1
        mergeBranch $brsrcBuildIntOfuat $brbuildingIntOfuat || return 1
        gcoBuildingIntOfuat
        
        if [ "$env" == "dev" ]; then
            cmdEnv="sit"
        fi
        
    elif [ "$env" == "prod" ]; then
        branch="$brbuildingIntOfprod"
        
        # gco $brsrcBuildIntOfprod
        # gp --no-edit || return 1
        checkoutBranch $brsrcBuildIntOfprod || return 1
        checkoutBranch $brbuildingIntOfprod || return 1
        mergeBranch $brsrcBuildIntOfprod $brbuildingIntOfprod || return 1
        gcoBuildingIntOfprod
    else
        echo "env = $env 参数错误"
        return 1
    fi
    
    clog "成功切换到组件包构建分支 ${branch} , 拉取最新代码..."
    
    gp
    
    local newVersion=`getIntNewVersion $env $pkshortName`
    
    wkproject $pkshortName || return 1

    
    local dt=`date +%Y-%m-%dT%H:%M:%S`
    
    sed -i "/${upperPkName}_VERSION/s/'[^\']*'/'${newVersion}@RTIME${dt}'/" ./src/index.js
    grep "${upperPkName}_VERSION" ./src/index.js
    
    clog "Index.js写入新版本号 $newVersion done"
    
    gcma "task#${taskId}: 升级gys-external-${pkshortName}组件包版本 $newVersion"
    gpp
    
    wkproject $pkshortName || return 1

    
    # local cmd="yarn lib:${env} -- --formats umd"
    local cmd="yarn lib:${cmdEnv}"
    
    clog "执行构建命令: $cmd"
    
    # yarn $cmd -- --formats umd
    $cmd
    
}

function getIntNewVersion() {
    usage 2 "${#@}" "getIntNewVersion <dev | uat | prod> <pkname>" || return 1

    local pkshortName=${2}
    pkproject $pkshortName || return 1
    
    local env="$1"
    if [ "$env" == "dev" -o "$env" == "uat" -o "$env" == "prod" ]; then
        gco $env &> /dev/null
        gp --no-edit &> /dev/null || return 1
    else
        echo "getIntNewVersion 分支参数非法 ( $env )"
        return 1
    fi
    
    cat package.json | grep "version" | awk -F '"' '{print $4}' | awk -F '[.-]' '{printf $1"."$2"."$3+1; if($4) printf "-"$4 }' > /tmp/newversion
    local newVersion=`cat /tmp/newversion`
    cd - > /dev/null
    
    echo $newVersion
}


function intcplib() {
    usage 2 ${#@} 'intcplib <dev | uat | prod> <pkname>' || return 1
    local pkshortName=${2}
    echo -e "\n\n 开始复制文件..."
    
    wkproject $pkshortName || return 1

    local env="$1"
    local libdir="$env"
    local buildDir="lib/${env}"
    
    if [ "$env" == "prod" ]; then
        local branch="$brbuildingIntOfprod"
    else
        local branch="$brbuildingIntOfuat"
        if [ "$env" == "dev" ]; then
            libdir="sit"
        fi
        
    fi
    
    pkproject $pkshortName || return 1
    
    gco $env
    clog "Lib仓库检出分支 ${env} done"
    gp
    
    
    # wk
    local pkdirVar="pkDir${pkshortName}"
    local targetDir="${!pkdirVar}/lib"

    echo rm -rf "lib"
    rm -rf "lib"
    echo "result $?"
    mkdir -p $targetDir
    
    clog "Lib仓库清理旧文件:: ${targetDir:7} done"


    pkproject $pkshortName || return 1
    
    wk $pkshortName || return 1
    if [ "$pkshortName" = 'invoice' ]; then
        cp -r ./projects/yth-integration/lib/${libdir}/group-int-platform-business* $targetDir
    elif [ "$pkshortName" = 'cost' ]; then
        cp -r ./projects/yth-co/lib/${libdir}/group-int-platform-business* $targetDir
    else
        echo "cplib pkname 参数非法 ${pkshortName}"
    fi

    clog "复制最新构建产物到Lib仓库 done"
    
    
    local newVersion=`getIntNewVersion $env $pkshortName`
    
    pkproject $pkshortName || return 1
    
    
    # cat package.json | grep "version" | awk -F '"' '{print $4}' | awk -F '[.-]' '{printf $1"."$2"."$3+1; if($4) printf "-"$4 }' > /tmp/newversion
    # local newVersion=`cat /tmp/newversion`
    # sed -i "s/\(\"version\":\s\+\"\)[^\"]\+\(\"\)/\1$newVersion\2/" package.json
    
    clog "新版本号为 ' $newVersion ' \n"
    
    gcma "chord: auto更新组件版本 $newVersion" --allow-empty
    
    echo "npm version $newVersion"

    npm version $newVersion
    
    clog "Lib仓库版本更新完成 新版本为 $newVersion"
    
    gpp
    
    clog "Lib仓库同步最新提交到远端 done"
}


function intpublib() {
    usage 2 ${#@} 'intpublib <dev | uat | prod> <pkname>' || return 1

    local pkshortName=${2}
    pkproject $pkshortName || return 1

    local branch="$1"
    local tag="$1"
    if [ "$branch" = "prod" ]; then
        tag="latest"
    fi
    
    gco $branch
    
    echo registry: `npm get registry`
    echo user: `npm whoami`
    
    echo "::: 开始发布 $tag 版本"
    
    npm publish --tag $tag
    
    if [ $? -ne 0 ]; then
        echo "::: 发布失败"
    else
        echo "::: 发布成功"
    fi
    
    npm info gys-external-${pkshortName} | head -30

}

# test
# -------------------------------------------------------------

function mytest() {
    wksrm
    dt=`date +%Y-%m-%dT%H:%M:%S`
    newVersion="$1"
    sed -i "/SRM_VERSION/s/'[^\']*'/'${newVersion}@RTIME:${dt}'/" ./src/index.js
    grep SRM_VERSION ./src/index.js
}

function mgtest() {
    mydev
    cd git-lm
    gco dev
    gm --no-edit master
    if [ "$?" -gt 0 ]; then
        echo 合并分支遇到冲突, 已撤销合并
        gm --abort
        return 1
    fi
    
    echo merge done!
}


function mymblib() {
    
    wksrm
    gcomain && gp
    gcoall && gp
    gcoboth
    
    gm --no-edit $brmain
    
    gm --no-edit $brall
    
    gcomy && gp
    
    gm --no-edit $brboth
    
    gpp
    
    
    gl -12 --oneline
    
}


function testtime() {
    t1=`date +%s`
    sleep ${1:-10}
    t2=`date +%s`
    echo "执行时间为: $(expr $t2 - $t1)秒"
}
